package ceha;

import ceha.ui.CehaApp;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;

public class MainApp extends JFrame implements ActionListener {

    JDesktopPane desktop;

    public MainApp() {
        initComponents();
        desktop = new JDesktopPane();
        createfiche();
        createmain();
        createdata();
        setContentPane(desktop);
        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
        JFrame.setDefaultLookAndFeelDecorated(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        int inset = 50;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset * 2);
//        desktop = new JDesktopPane();
    }

    protected void quit() {
        System.exit(0);
    }

    private void createdata() {
        DataMasterDetailForm tableframe = new DataMasterDetailForm();
        tableframe.getData().setVisible(true);

        desktop.add(tableframe.getData());
        try {
            tableframe.getData().setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    private void createfiche() {
        FicheJInternalFrame dataframe = new FicheJInternalFrame();
        dataframe.setVisible(true);
        desktop.add(dataframe);
        try {
            dataframe.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    private void createmain() {
        CehaApp mainframe = new CehaApp();
        mainframe.setVisible(true);
        desktop.add(mainframe);
        try {
            mainframe.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("cehaPU").createEntityManager();
        query = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT f FROM Fiche f");
        list = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        nouvellefiche = new javax.swing.JMenuItem();
        rechercherfiche = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jMenu1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jMenu1.setText("FICHE");

        nouvellefiche.setText("Nouvelle");
        jMenu1.add(nouvellefiche);

        rechercherfiche.setText("Rechercher");
        jMenu1.add(rechercherfiche);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("DONNEES");

        jMenuItem1.setText("Table");
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 889, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 527, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainApp().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private java.util.List<ceha.Fiche> list;
    private javax.swing.JMenuItem nouvellefiche;
    private javax.persistence.Query query;
    private javax.swing.JMenuItem rechercherfiche;
    // End of variables declaration//GEN-END:variables

    public void actionPerformed(ActionEvent e) {
    }
}
